package com.xgjweb.ac.effect
{
	import mx.effects.Parallel;
	import mx.effects.Rotate;
	import mx.effects.WipeDown;
	import mx.effects.WipeLeft;
	import mx.effects.WipeRight;
	import mx.effects.WipeUp;
	import mx.effects.Zoom;
	/**
	 *效果工具类，返回XgjWebEffect, XgjWebEffect包含beginEffect和endEffect,beginEffect表示，比如在show的时候执行
	 * beginEffect效果，hide的时候执行endEffect效果
	 * 
	 */
	public final class EffectUtil
	{
		public function EffectUtil()
		{
		}
		//随机选取效果常量
		private static   const   ZOOM:int=1;
		private static   const   ROTATE:int=2;
		//private static   const   ZOOM_RORATE:int=3;
		private static   const 	 WIPEDOWN:int=3;
		private static   const   WIPEUP:int=4;
		private static   const   WIPELEFT:int=5;
		private static   const   WIPERIGHT:int=6;
		private static   const   MAX_NUMBER:int=6;
		//预定义的效果
		public static   const   ZOOM_EFFECT:XgjWebEffect=zoomEffect();
		public static   const   ROTATE_EFFECT:XgjWebEffect=rotateEffect();
		//public static   const   ZOOM_RORATE_EFFECT:XgjWebEffect=zoomAndRotateEffect();
		public static   const   WIPEDOWN_EFFECT:XgjWebEffect=wipeDownEffect();
		public static   const   WIPEUP_EFFECT:XgjWebEffect=wipeUpEffect();
		public static   const   WIPELEFT_EFFECT:XgjWebEffect=wipeLeftEffect();
		public static   const   WIPERIGHT_EFFECT:XgjWebEffect=wipeRightEffect();
		
		//随机选取效果
		public static function randomEffect():XgjWebEffect{
			var value:Number=Math.ceil(Math.random()*MAX_NUMBER);
			switch(value){
				case ZOOM:
					return zoomEffect();
					break;
				case ROTATE:
					return rotateEffect();
					break;
				//case ZOOM_RORATE:
				//	return zoomAndRotateEffect();
				//	break;
				case WIPEDOWN:
					return wipeDownEffect();
					break;
				case WIPEUP:
					return wipeUpEffect();
					break;
				case WIPELEFT:
					return wipeLeftEffect();
					break;
				case WIPERIGHT:
					return wipeRightEffect();
					break;
			}
			return zoomEffect();
		}
		//Zoom 效果放大或缩小中心点上的对象
		private static function  zoomEffect():XgjWebEffect{
			var xgjWebEffect:XgjWebEffect=new XgjWebEffect();
			//开始
			var beginEffect:Zoom=new Zoom();
			beginEffect.zoomHeightFrom=0.3;
			beginEffect.zoomHeightTo=1.0;
			beginEffect.zoomWidthFrom=0.3
			beginEffect.zoomWidthTo=1.0;
			beginEffect.duration=1000;
			//结束
			var endEffect:Zoom=new Zoom();
			endEffect.zoomHeightFrom=1.0;
			endEffect.zoomHeightTo=0;
			endEffect.zoomWidthFrom=1.0;
			endEffect.zoomWidthTo=0;
			endEffect.duration=1000;
			//保存
			xgjWebEffect.beginEffect=beginEffect;
			xgjWebEffect.endEffect=endEffect;
			return xgjWebEffect;
		}
		//Rotate 效果可围绕指定的点旋转组件。您可以指定旋转中心的坐标以及旋转的起始角度和最终角度。
		//既可以指定正角度值，也可以指定负角度值。 
		private static function  rotateEffect():XgjWebEffect{
			var xgjWebEffect:XgjWebEffect=new XgjWebEffect();
			//开始
			var beginEffect:Rotate=new Rotate();
			beginEffect.angleFrom=0;
			beginEffect.angleTo=360;
			beginEffect.duration=1000;
			//结束
			var endEffect:Rotate=new Rotate();
			endEffect.angleFrom=360;
			endEffect.angleTo=0;
			endEffect.duration=1000;
			//保存
			xgjWebEffect.beginEffect=beginEffect;
			xgjWebEffect.endEffect=endEffect;
			return xgjWebEffect
		}
		
		//边旋转边缩放
		/*
		private static function  zoomAndRotateEffect():XgjWebEffect{
			var xgjWebEffect:XgjWebEffect=new XgjWebEffect();
			//开始
			var beginEffect:Parallel=new Parallel();
			var beginRoate:Rotate=new Rotate();
			var beginZoom:Zoom=new Zoom();
			beginRoate.angleFrom=0;
			beginRoate.angleTo=360;
			beginZoom.zoomHeightFrom=0;
			beginZoom.zoomHeightTo=1.0;
			beginZoom.zoomWidthFrom=0
			beginZoom.zoomWidthTo=1.0;
			beginEffect.addChild(beginRoate);
			beginEffect.addChild(beginZoom);
			//结束
			var endEffect:Parallel=new Parallel();
			var endRoate:Rotate=new Rotate();
			var endZoom:Zoom=new Zoom();
			endRoate.angleFrom=360;
			endRoate.angleTo=0;
			endZoom.zoomHeightFrom=1.0;
			endZoom.zoomHeightTo=0;
			endZoom.zoomWidthFrom=1.0
			endZoom.zoomWidthTo=0;
			endEffect.addChild(endRoate);
			endEffect.addChild(endZoom);
			//保存
			xgjWebEffect.beginEffect=beginEffect;
			xgjWebEffect.endEffect=endEffect;
			return xgjWebEffect
		}
		*/
		
		//WipeDown 类定义条形向下擦除效果。组件的 before 或 after 状态必须不可见
		private static function  wipeDownEffect():XgjWebEffect{
			var xgjWebEffect:XgjWebEffect=new XgjWebEffect();
			//开始
			var beginEffect:WipeDown=new WipeDown();
			beginEffect.duration=1000;
			//结束
			var endEffect:WipeDown=new WipeDown();
			endEffect.duration=1000;
			//保存
			xgjWebEffect.beginEffect=beginEffect;
			xgjWebEffect.endEffect=endEffect;
			return xgjWebEffect
		}
		
		//WipeLeft 类定义条形向左擦除效果。组件的 before 或 after 状态必须不可见
		private static function  wipeLeftEffect():XgjWebEffect{
			var xgjWebEffect:XgjWebEffect=new XgjWebEffect();
			//开始
			var beginEffect:WipeLeft =new WipeLeft ();
			beginEffect.duration=1000;
			//结束
			var endEffect:WipeLeft=new WipeLeft();
			endEffect.duration=1000;
			//保存
			xgjWebEffect.beginEffect=beginEffect;
			xgjWebEffect.endEffect=endEffect;
			return xgjWebEffect
		}
		
		//WipeRight 类定义条形向右擦除效果。组件的 before 或 after 状态必须不可见
		private static function  wipeRightEffect():XgjWebEffect{
			var xgjWebEffect:XgjWebEffect=new XgjWebEffect();
			//开始
			var beginEffect:WipeRight =new WipeRight ();
			beginEffect.duration=1000;
			//结束
			var endEffect:WipeRight=new WipeRight();
			endEffect.duration=1000;
			//保存
			xgjWebEffect.beginEffect=beginEffect;
			xgjWebEffect.endEffect=endEffect;
			return xgjWebEffect
		}
		
		//WipeUp 类定义条形向上擦除效果。组件的 before 或 after 状态必须不可见
		private static function  wipeUpEffect():XgjWebEffect{
			var xgjWebEffect:XgjWebEffect=new XgjWebEffect();
			//开始
			var beginEffect:WipeUp =new WipeUp ();
			beginEffect.duration=1000;
			//结束
			var endEffect:WipeUp=new WipeUp();
			endEffect.duration=1000;
			//保存
			xgjWebEffect.beginEffect=beginEffect;
			xgjWebEffect.endEffect=endEffect;
			return xgjWebEffect
		}
	}
}